package com.rpay.dao.question;

import com.rpay.model.question.AnswerDO;
import com.rpay.model.question.QuestionQueryDO;
import com.rpay.model.question.QuestionDO;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class QuestionDao {
    @Autowired
    @Qualifier("readSqlSession")
    private SqlSessionTemplate readSqlSession;

    @Autowired
    @Qualifier("writeSqlSession")
    private SqlSessionTemplate writeSqlSession;

    public List<QuestionDO> selectDataList(QuestionQueryDO questionQueryDO) {
        return readSqlSession.selectList("rpay.question.selectDataList", questionQueryDO);
    }

    public Integer selectCount(QuestionQueryDO questionQueryDO) {
        return readSqlSession.selectOne("rpay.question.selectCount", questionQueryDO);
    }

    public int insert(QuestionDO questionDO) {
        return writeSqlSession.insert("rpay.question.insert", questionDO);
    }

    public int insertAnswer(AnswerDO answerDO) {
        return writeSqlSession.insert("rpay.question.insertAnswer", answerDO);
    }

    public QuestionDO findById(QuestionDO questionDO) {
        return readSqlSession.selectOne("rpay.question.findById", questionDO);
    }

    public int deleteById(Integer id) {
        return writeSqlSession.update("rpay.question.deleteById", id);
    }

    public int deleteAnswerById(Integer id) {
        return writeSqlSession.update("rpay.question.deleteAnswerById", id);
    }

    public int updateById(QuestionDO questionDO) {
        return writeSqlSession.update("rpay.question.updateById", questionDO);
    }

    public int updateAnswerById(QuestionDO questionDO) {
        return writeSqlSession.update("rpay.question.updateAnswerById", questionDO);
    }
}
